package com.framework.network.annotations

import java.lang.annotation.Documented
import java.lang.reflect.Method

/**
 * @ClassName: TimeOut
 * @Description: 超时时间的注解，默认15秒
 * @Author: you
 */
@Documented
@Target(
    AnnotationTarget.FUNCTION,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.PROPERTY_SETTER
)
@Retention(AnnotationRetention.RUNTIME)
annotation class TimeOut(val timeout: Int = 15)

/**
 * 获取TimeOut的注解
 */
fun getTimeOut(method: Method): TimeOut? {
    val annotations = method.annotations
    for (annotation in annotations) {
        if (annotation is TimeOut) {
            return annotation
        }
    }
    return null
}

/**
 * 获取注解的值
 */
fun getTimeOutParameter(setTimeOut: TimeOut): Int {
    return setTimeOut.timeout
}